package com.DHH.Dto;


import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 通用分页传输通道
 * @param <T>
 */
public class PageInfo<T extends Serializable> implements Serializable{
	private List<T> rows;
	private long totalRow;
	private int totalPage;
	private int currentPage=1;
	private int pageSize=10;
	private int isFirstPage;
	private int isLastPage;
	private int hasPreviusPage;
	private int hasNextPage;
	private int previusPage;
	private int nextPage;
	private String msg;
	private String error;
	private Integer page;//该属性用于bootstrap-table分页
	private long total;//该属性用于bootstrap-table分页
	private List<Integer> pageList;
	public PageInfo(List<T> rows, int totalRow, int totalPage, int currentPage, int pageSize, int isFirstPage, int isLastPage, int hasPreviusPage, int hasNextPage) {
		this.rows = rows;
		this.totalRow = totalRow;
		this.totalPage = totalPage;
		this.currentPage = currentPage;
		this.pageSize = pageSize;
		this.isFirstPage = isFirstPage;
		this.isLastPage = isLastPage;
		this.hasPreviusPage = hasPreviusPage;
		this.hasNextPage = hasNextPage;
	}

	public PageInfo(List<T> rows) {
		this.rows = rows;
	}

	public PageInfo() {

	}

	public String getError() {
		return error;
	}

	public void setError(String error) {
		this.error = error;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public List<T> getRows() {
		return rows;
	}

	public void setRows(List<T> rows) {
		this.rows = rows;
	}

	public long getTotalRow() {
		return totalRow;
	}

	public void setTotalRow(long totalRow) {
		this.totalRow = totalRow;
		this.total = totalRow;
		if (currentPage == totalPage) {
			isLastPage = 1;
		}
		this.setTotalPage(((int) totalRow) % pageSize == 0 ? ((int) totalRow) / pageSize : (((int) totalRow) / pageSize) + 1);
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(long totalPage) {
		this.setPage((int) totalPage);
		this.totalPage = (int) totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
		this.page = totalPage;
		pageList = new ArrayList<Integer>();
		int temp = totalPage - currentPage - 2;
		int start = currentPage - 2 + (temp < 0 ? temp : 0);
		int n = 5 - ((start < 0 ? start : 0) - 1);
		for (int i = 0; i < n; i++) {
			if (start >= 1 && start <= totalPage) {
				pageList.add(start);
			}
			start++;
		}
		if (this.currentPage < totalPage) {
			this.nextPage = currentPage + 1;
			this.hasNextPage = 1;
		} else {
			this.hasNextPage = 0;
			this.nextPage = currentPage;
		}
		if (this.currentPage > 1) {
			this.previusPage = currentPage - 1;
			this.hasPreviusPage = 1;
		} else {
			this.previusPage = currentPage;
			this.hasPreviusPage = 0;
		}

	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getIsFirstPage() {
		return isFirstPage;
	}

	public void setIsFirstPage(int isFirstPage) {
		this.isFirstPage = isFirstPage;
	}

	public int getIsLastPage() {
		return isLastPage;
	}

	public void setIsLastPage(int isLastPage) {
		this.isLastPage = isLastPage;
	}

	public int getHasPreviusPage() {
		return hasPreviusPage;
	}

	public void setHasPreviusPage(int hasPreviusPage) {
		this.hasPreviusPage = hasPreviusPage;
	}

	public int getHasNextPage() {
		return hasNextPage;
	}

	public void setHasNextPage(int hasNextPage) {
		this.hasNextPage = hasNextPage;
	}

	public long getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}

	public void setTotal(long total) {
		this.total = total;
	}

	public Integer getPage() {
		return page;
	}

	public void setPage(Integer page) {
		this.page = page;
	}

	public List<Integer> getPageList() {
		return pageList;
	}

	public void setPageList(List<Integer> pageList) {
		this.pageList = pageList;
	}

	public int getPreviusPage() {
		return previusPage;
	}

	public void setPreviusPage(int previusPage) {
		this.previusPage = previusPage;
	}

	public int getNextPage() {
		return nextPage;
	}

	public void setNextPage(int nextPage) {
		this.nextPage = nextPage;
	}

	@Override
	public String toString() {
		return "PageInfo{" +
				"rows=" + rows +
				", totalRow=" + totalRow +
				", totalPage=" + totalPage +
				", currentPage=" + currentPage +
				", pageSize=" + pageSize +
				", isFirstPage=" + isFirstPage +
				", isLastPage=" + isLastPage +
				", hasPreviusPage=" + hasPreviusPage +
				", hasNextPage=" + hasNextPage +
				", previusPage=" + previusPage +
				", nextPage=" + nextPage +
				", msg='" + msg + '\'' +
				", error='" + error + '\'' +
				", page=" + page +
				", total=" + total +
				", pageList=" + pageList +
				'}';
	}
}
